package com.bsj.sipgateway.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bsj.power.common.config.exception.ApiException;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.config.global.JsonResultEnum;
import com.bsj.power.common.config.global.TokenUser;
import com.bsj.power.common.def.DeviceAddDTO;
import com.bsj.power.common.def.dto.Device2DDTO;
import com.bsj.power.common.def.dto.DeviceLightDTO;
import com.bsj.power.common.def.dto.RedisDeviceInfo;
import com.bsj.power.common.def.entity.Scene;
import com.bsj.power.common.def.entity.gb28181.Device;
import com.bsj.power.common.def.entity.gb28181.DeviceChannel;
import com.bsj.power.common.def.entity.log.VideoOpLog;
import com.bsj.power.common.def.enums.VideoOpTypeEnum;
import com.bsj.power.common.def.vo.*;
import com.bsj.power.common.mapper.DeviceChannelMapper;
import com.bsj.power.common.mapper.VideoOpLogMapper;
import com.bsj.power.common.util.DateUtils;
import com.bsj.power.common.util.ExceptionUtil;
import com.bsj.power.common.util.StpLoginUserUtil;
import com.bsj.power.common.util.StringUtils;
import com.bsj.sipgateway.common.constant.Constants;
import com.bsj.sipgateway.util.RedisDeviceInfoUtil;
import com.bsj.sipgateway.web.service.IDeviceService;
import com.bsj.sipgateway.web.service.ISceneService;
import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description 国标设备
 * @menu 国标设备
 * @Author zhaoyang
 * @Date 2024/4/25 19:37
 */
@Slf4j
@RestController
@RequestMapping("/api/device")
//@SaCheckPermission("/video/api/device")
public class ApiDeviceController {

    @Autowired
    @Qualifier("deviceServiceImpl")
    private IDeviceService iDeviceService;

    @Autowired
    @Qualifier("sceneServiceImpl")
    private ISceneService sceneService;

    @Autowired
    private RedisDeviceInfoUtil redisDeviceInfoUtil;

    @Autowired
    private DeviceChannelMapper deviceChannelMapper;

    @Autowired
    private VideoOpLogMapper videoOpLogMapper;

    /**
     * 根据id查询国标设备
     *
     * @param did 国标设备数据库id
     * @return: com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.entity.gb28181.VideoDevice>
     * @decription 根据id查询国标设备
     * @author zhaoyang
     * @date 2024/4/26 9:49
     */
    @GetMapping("/findByDid")
    private JsonResult<Device> findByDid(@RequestParam Long did) {
        Device device = iDeviceService.selectById(did);
        JsonResult<Device> result;
        if (device == null) {
            result = JsonResult.fail();
        } else {
            result = JsonResult.success();
            result.setData(device);
        }
        return result;
    }


    /**
     * 根据设备id查询多个国标设备
     *
     * @param dids 设备数据库id，多个英文逗号隔开
     * @return: com.bsj.power.common.config.global.JsonResult
     * @decription 根据设备id查询多个国标设备
     * @author zhaoyang
     * @date 2024/4/26 9:54
     */
    @GetMapping("/findListByDids")
    public JsonResult findDeviceList(@RequestParam Long[] dids) {
        JsonResult result;
        if (dids == null || dids.length == 0) {
            result = JsonResult.fail(JsonResultEnum.PARAM_ERROR);
        } else {
            List<Long> longs = Arrays.asList(dids);
            // 补充场景信息
            List<Device> devices = iDeviceService.selectDevicesByIds(longs);
            List<Integer> sceneIds = devices.stream().map(Device::getSceneId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(longs)) {
                result = new JsonResult<>();
                result.setCode(0);
                result.setTotal(0);
                result.setMsg("没有查询到数据");
                return result;
            }
            List<DeviceVO> deviceVOS = new ArrayList<>();
            if (!CollectionUtils.isEmpty(sceneIds)) {
                List<Scene> scenes = sceneService.selectScenesByIds(sceneIds);
                Map<Integer, Scene> sceneMap = scenes.stream().collect(Collectors.toMap(Scene::getId, Function.identity()));
                devices.forEach(device -> {
                    DeviceVO deviceVO = new DeviceVO();
                    BeanUtils.copyProperties(device, deviceVO);
                    // 写入场景名称
                    Scene scene = sceneMap.get(device.getSceneId());
                    if (scene != null) {
                        device.setSceneName(scene.getSceneName());
                        deviceVO.setSceneName(scene.getSceneName());
                    }
                    // 获取在线离线信息（查缓存）
                    boolean onlineFlag = redisDeviceInfoUtil.checkOnline(device.getDeviceId());
                    if (onlineFlag) {
                        device.setOnline(Constants.DEVICE_ONLINE);
                        deviceVO.setOnline(Constants.DEVICE_ONLINE);
                    } else {
                        device.setOnline(Constants.DEVICE_OFFLINE);
                        deviceVO.setOnline(Constants.DEVICE_OFFLINE);
                    }
                    // 获取云台锁定状态（查缓存）
                    String lockedStr = redisDeviceInfoUtil.getPtzControlLock(device.getDeviceId());
                    if (!StringUtil.isEmpty(lockedStr)) {
                        String[] s = lockedStr.split("_");
                        device.setPtzControlLock(1);
                        deviceVO.setPtzControlLock(1); // 锁定
                        deviceVO.setLockUid(Integer.parseInt(s[0])); // 用户id
                        deviceVO.setLockedUserWeight(Integer.parseInt(s[1])); // 用户权重
                    } else {
                        device.setPtzControlLock(0); // 未锁定
                        deviceVO.setPtzControlLock(0);
                    }
                    deviceVOS.add(deviceVO);
                });
            }
            result = JsonResult.success(JsonResultEnum.SUCCESS);
            result.setTotal(devices.size());
            result.setData(deviceVOS);
        }
        return result;
    }


    /**
     * 分页查询国标设备
     *
     * @param page      分页条件
     * @param size      分页条件
     * @param condition 查询条件 字符串 根据设备编号和设备名称模糊查询
     * @param roomNo    房间号查询条件 字符串
     * @return: com.bsj.power.common.config.global.JsonResult
     * @decription 分页查询国标设备
     * @author zhaoyang
     * @date 2024/4/26 9:54
     */
    @GetMapping("/findList")
    public JsonResult findVideoDeviceList(@RequestParam Integer page, @RequestParam Integer size
            , @RequestParam(required = false) String condition, @RequestParam(required = false) String roomNo) {
        JsonResult result;
        if (page == null || size == null) {
            result = JsonResult.fail(JsonResultEnum.PARAM_ERROR);
        } else {
            IPage<Device> iPage = iDeviceService.queryPageVideoDeviceList(page, size, condition, roomNo);
            // 补充场景信息
            List<Device> devices = iPage.getRecords();
            List<Long> dids = devices.stream().map(Device::getId).collect(Collectors.toList());
            List<Integer> sceneIds = devices.stream().map(Device::getSceneId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(dids)) {
                result = new JsonResult<>();
                result.setCode(-1);
                result.setMsg("没有查询到数据");
                return result;
            }
            List<DeviceVO> deviceVOS = new ArrayList<>();
            if (!CollectionUtils.isEmpty(sceneIds)) {
                List<Scene> scenes = sceneService.selectScenesByIds(sceneIds);
                Map<Integer, Scene> sceneMap = scenes.stream().collect(Collectors.toMap(Scene::getId, Function.identity()));
                devices.forEach(device -> {
                    DeviceVO deviceVO = new DeviceVO();
                    BeanUtils.copyProperties(device, deviceVO);
                    // 写入场景名称
                    Scene scene = sceneMap.get(device.getSceneId());
                    if (scene != null) {
                        device.setSceneName(scene.getSceneName());
                        deviceVO.setSceneName(scene.getSceneName());
                    }
                    // 获取在线离线信息（查缓存）
                    boolean onlineFlag = redisDeviceInfoUtil.checkOnline(device.getDeviceId());
                    if (onlineFlag) {
                        deviceVO.setOnline(Constants.DEVICE_ONLINE);
                    } else {
                        deviceVO.setOnline(Constants.DEVICE_OFFLINE);
                    }

                    RedisDeviceInfo redisDeviceInfo = redisDeviceInfoUtil.getRedisDeviceInfo(device.getDeviceId());
                    if (redisDeviceInfo != null) {
                        long keepAliveTime = redisDeviceInfo.getKeepAliveTime();
                        if (keepAliveTime != 0) {
                            deviceVO.setLastRegisterTime(DateUtils.dateToStr(new Date(keepAliveTime)));
                        }
                        Long registerTime = redisDeviceInfo.getRegisterTime();
                        if (registerTime != null) {
                            deviceVO.setLastLoginTime(DateUtils.dateToStr(new Date(registerTime)));
                        }
                    }

                    // 获取云台锁定状态（查缓存）
                    String lockedStr = redisDeviceInfoUtil.getPtzControlLock(device.getDeviceId());
                    if (!StringUtil.isEmpty(lockedStr)) {
                        String[] s = lockedStr.split("_");
                        deviceVO.setPtzControlLock(1); // 锁定
                        deviceVO.setLockUid(Integer.parseInt(s[0]));
                        deviceVO.setLockedUserWeight(Integer.parseInt(s[1]));
                    } else {
                        deviceVO.setPtzControlLock(0); // 未锁定
                    }

                    // 获取通道信息
                    List<DeviceChannel> deviceChannels = deviceChannelMapper.queryAllChannels(device.getDeviceId());
                    deviceVO.setDeviceChannels(deviceChannels);

                    deviceVOS.add(deviceVO);
                });
            }
            result = JsonResult.success(JsonResultEnum.SUCCESS);
            result.setTotal(iPage.getTotal());
            result.setData(deviceVOS);
        }
        return result;
    }

    /**
     * 根据设备编号和设备名称模糊搜索设备信息
     *
     * @param condition
     * @return
     */
    @RequestMapping("/findDeviceByCondition")
    public JsonResult findDeviceByCondition(@RequestParam String condition) {
        JsonResult jsonResult = new JsonResult();
        if (condition == null) {
            jsonResult.setCode(-1);
            jsonResult.setMsg("条件为空，暂不查询");
            return jsonResult;
        }
        List<Device> devices = iDeviceService.findDeviceByCondition(condition);
        if (CollectionUtils.isEmpty(devices)) {
            jsonResult.setCode(-1);
            jsonResult.setMsg("没有查询到符合条件的数据");
            return jsonResult;
        }
        List<SimpleDeviceVO> vos = new ArrayList<>();
        devices.forEach(device -> {
            SimpleDeviceVO simpleDeviceVO = new SimpleDeviceVO();
            BeanUtils.copyProperties(device, simpleDeviceVO);
            vos.add(simpleDeviceVO);
        });
        jsonResult.setCode(JsonResultEnum.SUCCESS.getCode());
        jsonResult.setMsg(JsonResultEnum.SUCCESS.getMsg());
        jsonResult.setData(vos);
        jsonResult.setTotal(vos.size());
        return jsonResult;
    }


    /**
     * 添加国标设备信息
     *
     * @param dto
     * @return: com.bsj.power.common.config.global.JsonResult
     * @decription
     * @author zhaoyang
     * @date 2024/7/15 16:17
     */
    @PostMapping("/add")
    public JsonResult addDevice(@RequestBody DeviceAddDTO dto) {
        if (dto == null || dto.getSceneId() == null || dto.getCameraType() == null || dto.getNickName() == null
                || StringUtil.isEmpty(dto.getPointJson())
                || dto.getDeviceId() == null || dto.getDeviceId().length() != 20) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        boolean exist = iDeviceService.deviceIdisExist(dto.getDeviceId());
        if (exist) {
            throw new ApiException(JsonResultEnum.DEVICE_ID_EXIST);
        }
        boolean nickNameExist = iDeviceService.nickNameIsExist(dto.getNickName());
        if (nickNameExist) {
            throw new ApiException(JsonResultEnum.DEVICE_NAME_EXIST);
        }
        int count = iDeviceService.addDevice(dto);
        if (count != 0) {
            return JsonResult.success();
        }
        return JsonResult.fail();
    }

    /**
     * 更新国标设备信息
     *
     * @param device
     * @return: com.bsj.power.common.config.global.JsonResult
     * @decription 更新国标设备信息
     * @author zhaoyang
     * @date 2024/5/9 11:54
     */
    @PostMapping("/update")
    public JsonResult updateDevice(@RequestBody Device device) {
        if (device == null || device.getSceneId() == null || device.getNickName() == null
                || device.getDeviceId() == null || device.getDeviceId().length() != 20) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        if (device == null || device.getId() == null || StringUtil.isEmpty(device.getNickName())) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        iDeviceService.updateDevice(device);
        return JsonResult.success();
    }


    /**
     * 删除设备
     *
     * @param id 国标设备数据库id
     * @return: com.bsj.power.common.config.global.JsonResult
     * @decription 移除设备
     * @author zhaoyang
     * @date 2024/4/27 19:54
     */
    @RequestMapping("/deleteDevice")
    public JsonResult deleteDevice(@RequestParam Integer id) {
        boolean isSuccess = iDeviceService.delete(id);
        if (isSuccess) {
            JsonResult result = JsonResult.success();
            return result;
        } else {
            log.warn("设备信息删除API调用失败！");
            throw new ApiException(JsonResultEnum.FAIL);
        }
    }


    /**
     * 根据场景id查询设备的监控状态
     *
     * @param sceneId
     * @return: com.bsj.power.common.config.global.JsonResult
     * @decription
     * @author zhaoyang
     * @date 2024/6/26 20:42
     */
    @RequestMapping("/deviceStatusMonitor")
    public JsonResult deviceStatusMonitor(@RequestParam(required = false) Integer sceneId
            , @RequestParam(required = false) String condition
            , @RequestParam Integer pageNumber
            , @RequestParam Integer pageSize) {
        if (sceneId == null && StringUtils.isEmpty(condition)) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        IPage<Device> iPage = sceneService.listDeviceBySceneIdAndCondition(sceneId, condition, pageNumber, pageSize);
        List<Device> devices = iPage.getRecords();
        if (CollectionUtils.isEmpty(devices)) {
            JsonResult jsonResult = new JsonResult();
            jsonResult.setCode(-1);
            jsonResult.setMsg("暂无数据");
            return jsonResult;
        }
        List<DeviceStatusMonitorVO> vos = new ArrayList<>();
        long now = System.currentTimeMillis() / 1000;
        for (Device device : devices) {
            DeviceStatusMonitorVO vo = new DeviceStatusMonitorVO();
            vo.setRoomNo(device.getRoomNo());
            vo.setId(device.getId());
            vo.setDeviceId(device.getDeviceId());
            vo.setNickName(device.getNickName());
            String lockedStr = redisDeviceInfoUtil.getPtzControlLock(vo.getDeviceId());
            if (!StringUtil.isEmpty(lockedStr)) {
                String[] s = lockedStr.split("_");
                vo.setPtzControlLock(1);
                vo.setLockedUserWeight(Integer.parseInt(s[1])); // 用户权重
            } else {
                vo.setPtzControlLock(0);
            }

            RedisDeviceInfo redisDeviceInfo = redisDeviceInfoUtil.getRedisDeviceInfo(device.getDeviceId());
            if (redisDeviceInfo == null) {
                vo.setWorkTime("--");
                vo.setOnline(Constants.DEVICE_OFFLINE);
            } else {
                boolean onlineFlag = redisDeviceInfo.getOnline() == Constants.DEVICE_ONLINE
                        && (System.currentTimeMillis() - redisDeviceInfo.getKeepAliveTime()) < 180000L;
                if (onlineFlag) {
                    vo.setOnline(Constants.DEVICE_ONLINE);
                    Long registerTime = redisDeviceInfo.getRegisterTime() / 1000;
                    String secToTime = DateUtils.secToTime((int) (now - registerTime));
                    vo.setWorkTime(secToTime);
                } else {
                    // 离线分为异常离线和正常离线
                    vo.setOnline(Constants.DEVICE_OFFLINE);
                    String timeStr = null;
                    if (redisDeviceInfo.getOnline() == Constants.DEVICE_ONLINE) { // 设备掉电或者系统宕机以后从未上线
                        long keepAliveTime = redisDeviceInfo.getKeepAliveTime() / 1000;
                        timeStr = DateUtils.secToTime((int) (now - keepAliveTime));
                    } else { // 正常离线
                        Long logoutTime = redisDeviceInfo.getLogoutTime();
                        if (logoutTime != null) {
                            timeStr = DateUtils.secToTime((int) (now - logoutTime / 1000));
                        }
                    }
                    vo.setWorkTime(timeStr);
                }
                vo.setDeviceAbnormalOffline(redisDeviceInfo.getDeviceAbnormalOffline());
            }
            vo.setPictureQuality(device.getResolution());
            vos.add(vo);
        }
        JsonResult result = new JsonResult();
        result.setCode(JsonResultEnum.SUCCESS.getCode());
        result.setMsg(JsonResultEnum.SUCCESS.getMsg());
        result.setData(vos);
        result.setTotal(iPage.getTotal());
        return result;
    }

    /**
     * 修改设备亮度等参数
     *
     * @param deviceLightDTO
     * @return
     */
    @PostMapping("/updateDeviceLight")
    public JsonResult updateDeviceLight(@RequestBody DeviceLightDTO deviceLightDTO) {
        boolean flag = iDeviceService.updateDeviceLight(deviceLightDTO);
        if (flag) {
            return JsonResult.success();
        }
        return JsonResult.fail();
    }


    /**
     * 查询设备的亮度等参数
     *
     * @param deviceId
     * @return
     */
    @GetMapping("/getDeviceLightVO")
    public JsonResult<DeviceLightVO> getDeviceLightVO(@RequestParam String deviceId) {
        DeviceLightVO deviceLightVO = iDeviceService.getDeviceLightVO(deviceId);
        if (deviceLightVO != null) {
            JsonResult jsonResult = JsonResult.success();
            jsonResult.setData(deviceLightVO);
            return jsonResult;
        }
        return JsonResult.fail();
    }

    /**
     * 批量修改设备二维位置数据
     *
     * @param device2DDTOS
     * @return
     */
    @PostMapping("/updateDevice2d")
    public JsonResult updateDevice2dInfo(@RequestBody List<Device2DDTO> device2DDTOS) {
        if (device2DDTOS.size() == 0) {
            return JsonResult.fail(JsonResultEnum.PARAM_ERROR);
        }
        return iDeviceService.updateDevice2dInfo(device2DDTOS);
    }

    /**
     * 删除设备二维位置数据
     *
     * @param ids
     * @return
     */
    @GetMapping("/deleteDevice2d")
    public JsonResult deleteDevice2dInfo(@RequestParam Long[] ids) {
        if (ids == null || ids.length < 1) {
            return JsonResult.fail(JsonResultEnum.PARAM_ERROR.getMsg());
        }
        List<Long> longs = Arrays.asList(ids);
        return iDeviceService.deleteDevice2dInfo(longs);
    }

    /**
     * 根据栋数和楼层查询设备二维信息
     *
     * @param building
     * @param floor
     * @return
     */
    @GetMapping("/listDevice2DInfo")
    public JsonResult<TwoDDeviceInfoVO> listDevice2DInfo(@RequestParam Integer building, @RequestParam Integer floor) {
        return iDeviceService.listDevice2DInfo(building, floor);
    }

    /**
     * 获取单个设备的通道信息
     *
     * @param deviceId
     * @return
     */
    @GetMapping("/queryChannelDeviceByDeviceId")
    public JsonResult<List<DeviceChannel>> queryChannelDeviceByDeviceId(String deviceId) {
        List<DeviceChannel> deviceChannels = deviceChannelMapper.queryAllChannels(deviceId);
        if (CollectionUtils.isEmpty(deviceChannels)) {
            JsonResult jsonResult = new JsonResult();
            jsonResult.setCode(-1);
            jsonResult.setMsg("暂无通道信息");
            return jsonResult;
        }
        JsonResult jsonResult = JsonResult.success();
        jsonResult.setData(deviceChannels);
        return jsonResult;
    }

    /**
     * 修改流媒体通道的类型
     *
     * @param deviceId  国标设备id
     * @param channelId 国标通道id
     * @param mediaType 媒体类型
     * @param serialNum 逻辑通道号 默认1是云台 2是全景
     * @return
     */
    @GetMapping("/updateChannelDevice")
    public JsonResult updateChannelDevice(String deviceId, String channelId, String mediaType, Integer serialNum) {
//        DeviceChannel deviceChannel = deviceChannelMapper.selectByDeviceIdAndChannelId(deviceId, channelId);
//        JsonResult jsonResult = null;
//        if (deviceChannel == null) {
//            jsonResult = JsonResult.fail();
//            jsonResult.setMsg("没有查询到通道信息");
//            return jsonResult;
//        }
//
//        if (mediaType.equals(deviceChannel.getMediaType())) {
//            jsonResult = JsonResult.fail();
//            jsonResult.setMsg("类型相同无需修改");
//            return jsonResult;
//        }
        if (serialNum == null) {
            serialNum = 1;
        }
        int row = deviceChannelMapper.updateChannelDevice(deviceId, channelId, mediaType, serialNum);
        if (row > 0) {
            try {
                Device device = iDeviceService.selectByDeviceId(deviceId);
                TokenUser tokenInfo = StpLoginUserUtil.getTokenUser();
                int type = VideoOpTypeEnum.SETTING.getOpType();
//                String content = "视频类型由" + deviceChannel.getMediaType() + "改为" + mediaType;
                String controlStr = serialNum == 1 ? "是" : "否";
                String content = "视频类型改为" + mediaType + ",云台类型改为" + controlStr;
                if (tokenInfo != null && !StringUtils.isEmpty(content)) {
                    VideoOpLog videoOpLog = new VideoOpLog();
                    videoOpLog.setDeviceId(deviceId);
                    videoOpLog.setName(VideoOpTypeEnum.getByValue(type));
                    videoOpLog.setOpUserId(tokenInfo.getUserId());
                    videoOpLog.setOpUserName(tokenInfo.getUserName());
                    videoOpLog.setOpType(type);
                    videoOpLog.setOpTime(new Date());
                    videoOpLog.setContent(content);
                    videoOpLog.setNickName(device.getNickName());
                    videoOpLog.setEquipmentNumber(device.getEquipmentNumber());
                    videoOpLogMapper.insert(videoOpLog);
                }
            } catch (Exception e) {
                log.error("记录日志失败：{}", ExceptionUtil.getStackStr(e));
            }

            return JsonResult.success();
        }
        return JsonResult.fail();

    }

    /**
     * 根据id删除设备通道信息
     *
     * @param id
     * @return
     */
    @GetMapping("/deleteDeviceChannelById")
    public JsonResult deleteDeviceChannelById(Integer id) {
        if (id == null) {
            return JsonResult.fail(JsonResultEnum.PARAM_ERROR);
        }
        int row = deviceChannelMapper.deleteById(id);
        if (row > 0) {
            return JsonResult.success();
        }
        return JsonResult.fail();
    }

    /**
     * 添加预添加设备信息
     *
     * @param deviceId 国标设备id
     * @return
     */
    @GetMapping("/addPrepareDevice")
    public JsonResult addPrepareDevice(String deviceId) {
        if (StringUtils.isEmpty(deviceId)) {
            return JsonResult.fail(JsonResultEnum.PARAM_ERROR);
        }
        if (deviceId.length() != 20) {
            JsonResult jsonResult = JsonResult.fail();
            jsonResult.setMsg("国标id长度不够20位");
            return jsonResult;
        }
        return iDeviceService.addPrepareDevice(deviceId);
    }

    /**
     * 根据id删除预添加设备信息
     *
     * @param id 数据库id
     * @return
     */
    @GetMapping("/deletePrepareDevice")
    public JsonResult deletePrepareDevice(Integer id) {
        if (id == null) {
            return JsonResult.fail(JsonResultEnum.PARAM_ERROR);
        }
        return iDeviceService.deletePrepareDevice(id);
    }

    /**
     * 分页查询预添加设备信息
     *
     * @param condition 设备编号模糊搜索
     * @param pageNumber 页码
     * @param pageSize 条数
     * @return
     */
    @GetMapping("/listPrepareDevice")
    public JsonResult listPrepareDevice(String condition, Integer pageNumber, Integer pageSize) {
        if (pageNumber == null || pageSize == null) {
            return JsonResult.fail(JsonResultEnum.PARAM_ERROR);
        }
        return iDeviceService.listPrepareDevice(pageNumber, pageSize, condition);
    }


}
